<#import "../macro/components.ftl" as components/>
<#include "../macro/layout_default.ftl"/>

<@head>
<link rel="stylesheet" href="/misc/app/css/product_list.css"/>
<link rel="stylesheet" href="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.css"/>
</@head>

<@body>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/moment.min.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.js"></script>
<script src="/misc/jquery-fileupload-9.14.0/jquery.ui.widget.js"></script>
<script src="/misc/jquery-fileupload-9.14.0/jquery.fileupload.js"></script>
<script>var PicDomain = "${PicDomain!}"</script>

<script src="/misc/app/js/activity_new.js"></script>
<script src="/misc/app/js/activity_edit.js"></script>
</@body>

<@layout_default>



<div class="box" name="md_edit_activity">
  <!-- Nav tabs -->
  <ul class="nav nav-tabs" role="tablist">
    <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">活动详情</a>
    </li>

    <li role="presentation">
        <a href="/activity/getActivityPrizeList?activityId=${activity.id?c}">中奖规则</a>
    </li>
    <li role="presentation"><a href="/activity/getActivityAbstract?activityId=${activity.id?c}">活动规则</a></li>
  </ul>

  <div class="tab-content">
    <div role="tabpanel" class="tab-pane active" id="home">
      <div class="box-header with-border"></div>
      <div class="box-body">
        <form class="form-horizontal" name="form_edit_activity">
          <input type="hidden" name="id" id="activityId" value="${activity.id?c}"/>
          <#--<input type="hidden" name="actTimeStart" id="actTimeStart"-->
                 <#--value="${activity.actTimeStart?number_to_datetime!}"/>-->
          <#--<input type="hidden" name="actTimeEnd" id="actTimeEnd"-->
                 <#--value="${activity.actTimeEnd?number_to_datetime!}"/>-->
          <input type="hidden" id="channel_edit" value="${activity.channel!}"/>
          <input type="hidden" id="backgroundImage1" value="${activity.backgroundImageGet!}"/>
          <input type="hidden" id="backgroundImageWin" value="${activity.backgroundImageWin!}"/>
          <input type="hidden" id="backgroundImageLos" value="${activity.backgroundImageLos!}"/>
          <input type="hidden" id="isAutoDraw_hidden" value="${activity.isAutoDraw!}"/>
          <input type="hidden" id="regFlag" value="${regFlag}"/> <!--标记是否有活动区域关联记录 1有，0没有-->
          <!--<input type="hidden" id="prosFlag" value="${prosFlag}"/>标记是否有活动商品关联记录 1有，0没有-->


          <div class="form-group">
            <label class="col-sm-2 control-label" name="namelabel"><strong class="text-red bold">*</strong>
              活动名称</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="活动名称" name="name" value="${activity.name!}" maxlength="200" />
            </div>
          </div>
          <div class="form-group" id="regionDiv">
            <label class="col-sm-2 control-label"><strong class="text-red bold">*</strong> 活动区域</label>
            <div class="col-sm-10">
              <select class="" id="province" name="provinceId" style="width:15%;height:25px;">
                <option value="">请选择省</option>
              </select>
              <select class="" id="city" name="cityId" style="width:15%;height:25px;">
                <option value="">请选择市</option>
              </select>
              <select class="" id="county" name="countyId" style="width:15%;height:25px;">
                <option value="">请选择区县</option>
              </select>

              <button type="button" class="btn-default" name="btn_add_regionDiv">
                <i class="fa fa-plus"></i>添加
              </button>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-10">
              <#if selectedRgnList?exists>
                <#list selectedRgnList as item>
                  <tr>
                    <td>
                    ${item.selectRgn}
                      <button type="button" class="btn btn-default btn-xs" name="btn_edit_activity_delRgn"
                              data-rgn-id="${item.id}">删除
                      </button>&nbsp;&nbsp;&nbsp;
                    </td>
                  </tr>
                </#list>
              </#if>
            </div>
          </div>
          
          <div class="form-group">
            <label class="col-sm-2 control-label"><strong class="text-red bold">*</strong>活动时间</label>
            <#if activity.sta == 1 && .now?long gt activity.actTimeStart>

                  <div class="col-sm-1" style="width:170px;">
                      <input type="text"  value="${activity.actTimeStart?number_to_date?string("yyyy-MM-dd HH:mm:ss")}" class="activity_start_edit" size="20" readonly="readonly">
                  </div>

            <#else >
                <div class="col-sm-1" style="width:170px;">
                    <input type="text" id="activity_start_edit" class="activity_start_edit" size="20" value="${activity.actTimeStart?number_to_date?string("yyyy-MM-dd HH:mm:ss")}">
                </div>
            </#if>


            <div class="col-sm-1" style="width:10px;text-align:center;padding-top:5px;">
              至
            </div>
            <div class="col-sm-2">
              <input type="text" id="activity_end_edit" class="" size="20" value="${activity.actTimeEnd?number_to_date?string("yyyy-MM-dd HH:mm:ss")}">
            </div>
          </div>
          <div class="form-group">
	        <label class="col-sm-2 control-label" name="namelabel">自动抽奖</label>
	        <div class="col-sm-5" style="padding-top:7px;">
	          <input type="radio" name="isAutoDraw" id="radio_yes" value="1" runat="server" />是&nbsp;&nbsp;&nbsp;&nbsp;
	          <input type="radio" name="isAutoDraw" id="radio_no" value="0" runat="server" />否
	        </div>
	      </div>
          
          <div class="form-group" id="get_div">
            <label class="col-sm-2 control-label">抽奖背景图</label>
            <div class="col-sm-10">
              <p class="help-block"><i class="fa fa-info-circle text-yellow"></i>点击预览图可删除图片，
                图片数量限制1张，图片尺寸：640*1030</p>
              <span class="ctn-product-pics" id="ctn_edit_product_pics"></span>
              <input type="file" id="ipt_edit_product_upload_pic" class="hide" name="file"/>
              <button type="button" class="btn-upload-productimg" name="btn_edit_product_upload_pic"><i
                  class="fa fa-plus"></i></button>
              <div style="clear:both;"></div>
              <span class="btn btn-default btn-xs" data-toggle="modal" data-target="#preview_dialog"
                    name="btn_new_preview" data-url="/misc/app/html/index.html">预览</span>
            </div>
          </div>
          
          <div class="form-group" id="win_div">
            <label class="col-sm-2 control-label">中奖背景图</label>
            <div class="col-sm-10">
              <p class="help-block"><i class="fa fa-info-circle text-yellow"></i>点击预览图可删除图片，
                图片数量限制1张，图片尺寸：640*1030</p>
              <span class="ctn-product-pics" id="ctn_edit_product_pics_win"></span>
              <input type="file" id="ipt_edit_product_upload_pic_win" class="hide" name="file"/>
              <button type="button" class="btn-upload-productimg" name="btn_edit_product_upload_pic_win"><i
                  class="fa fa-plus"></i></button>
              <div style="clear:both;"></div>
              <span class="btn btn-default btn-xs" name="btn_new_preview" data-url="/misc/app/html/win.html"
                    data-toggle="modal" data-target="#preview_dialog">预览</span>
            </div>
          </div>
         <div class="form-group" id="nowin_div">
	        <label class="col-sm-2 control-label">未中奖背景图</label>
	        <div class="col-sm-10">
	          <p class="help-block"><i class="fa fa-info-circle text-yellow"></i>点击预览图可删除图片，图片数量限制1张，图片尺寸：640*1030</p>
	          <span class="ctn-product-pics" id="ctn_edit_product_pics_nowin"></span>
	          <input type="file" id="ipt_edit_product_upload_pic_nowin" class="hide" name="file"/>
	          <button type="button" class="btn-upload-productimg" name="btn_edit_product_upload_pic_nowin"><i
	              class="fa fa-plus"></i></button>
	          <div style="clear:both;"></div>
	          <span class="btn btn-default btn-xs" name="btn_new_preview" data-url="/misc/app/html/nowin.html"
	                data-toggle="modal" data-target="#preview_dialog">预览</span>
	        </div>
     	 </div>
			<div class="form-group">
            <label class="col-sm-2 control-label"><strong class="text-red bold">*</strong> 渠道</label>
            <div class="col-sm-10" style="padding-top:5px;">
              <input type="checkbox" value="商超" name="channel"/>商超
              <input type="checkbox" value="酒店" name="channel"/>酒店
              <input type="checkbox" value="名烟名酒行" name="channel"/>名烟名酒行
              <input type="checkbox" value="传统批发" name="channel"/>传统批发
              <input type="checkbox" value="自定义" name="channel" id="chk_custom"/>自定义
              <input type="text" id="channel_custom" maxlength="20" />
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" name="namelabel"><strong class="text-red bold">*</strong>
              参奖基数</label>
            <div class="col-sm-10">
              <input type="text" class="form-control" placeholder="参奖基数" name="actBaseNub"
                     value="${activity.actBaseNub}" maxlength="10"
                <#if activity.sta == 1 && .now?long gt activity.actTimeStart> readonly="readonly"</#if>/>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label"><strong class="text-red bold">*</strong> 活动商品</label>
            <div class="col-sm-10">
              <button type="button" class="btn btn-default" name="btn_select_product" data-toggle="modal"
                      data-target="#selectedProduct_modals"><i class="fa fa-plus"></i> 选择商品
              </button>
            </div>
          </div>

          <div class="form-group" id="selectedProDiv">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-10">
              <table class="table table-striped table-hover">
                <thead>
                <tr>
                  <th>ID</th>
                  <th>名称</th>
                  <th>编号</th>
                  <th>条码</th>
                  <th>品牌</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="product_table">
                  <#if selectedProductList?exists>
                    <#list selectedProductList as item1>
                    <tr>
                      <td>${item1.id}</td>
                      <td>${item1.name}</td>
                      <td>${item1.number}</td>
                      <td>${item1.barcode}</td>
                      <td>${item1.brandName!}</td>
                      <td>
                        <button type="button" class="btn btn-default btn-xs" name="btn_delete_activity_product"
                                data-activity-product-id="${item1.id?c}" onclick="del(${item1.id?c},this)">删除
                        </button>
                      </td>
                    </tr>
                    </#list>
                  </#if>
                </tbody>
              </table>
            </div>
          </div>
        </form>
      </div>
      <div class="box-footer text-center">
        <button type="button" class="btn btn-default" name="btn_cancel_edit_activity">取消</button>
        <button type="button" class="btn btn-primary" name="btn_save_edit_activity">保存</button>
      </div>

    </div>
  </div>


</div>


<!--===========Modals  点击“选择商品”按钮，显示商品列表   start================--->
<div class="modal" id="selectedProduct_modals" tabindex="-1">
  <div class="modal-dialog" role="document" style="width:700px;">
    <div class="modal-content">
      <div class="modal-header">
      	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h5 class="modal-title"><i class="fa fa-plus"></i> 选择商品</h5>
      </div>
      <span class="pull-right text-muted" style="margin: 14px 10px 0 0;">共 ${productList1.resultTotal} 条记录</span>
      <form class="form-inline" action="">
        <div class="input-group">
          <div class="input-group-addon">关键字</div>
          <input type="text" class="form-control" style="width: 260px" name="keyword" value="${keyword!}"
                 placeholder="名称、编号、品牌"/>
        </div>

        <button type="button" class="btn btn-warning" name="pro_query"><i class="fa fa-search"></i> 查询</button>
      </form>
      <div class="modal-body">
        <table class="table table-striped table-hover">
          <thead>
          <tr>
            <th><input type="checkbox" id="selectAll" name="selectAll"/></th>
            <th>ID</th>
            <th>名称</th>
            <th>编号</th>
            <th>条码</th>
            <th>品牌</th>
            <th>是否可用</th>
          </tr>
          </thead>
          <tbody id="product_model">
            <#list productList1.result as item>
            <tr>
              <td>
                <!--商品没有其它活动关联中，则商品可用-->
                <#if item.activityProductIdIsExists==0>
                  <input type="checkbox" name="product" value="${item.id!}"/>
                </#if><!--state2:1说明有未过期的记录，0 无未过期的记录-->
                <!--商品已关联了其它活动，但活动处于停用状态，则商品可用; 活动处于正常启用状态，但活动已过期结束 ，则商品可用-->
                <#if item.activityProductIdIsExists == 1 && item.state1 == 0 && item.state2==0>
                  <input type="checkbox" name="product" value="${item.id!}"/>
                </#if>
              </td>
              <td>${item.id}</td>
              <td class="name_${item.id!}">${item.name}</td>
              <td class="number_${item.id!}">${item.number}</td>
              <td class="bar_${item.id!}">${item.barcode}</td>
              <td class="brand_${item.id!}">${item.brandName!}</td>
              <td><!--state2:1说明有未过期的记录，0 无未过期的记录-->
                <#if item.activityProductIdIsExists==0>可用
                <#elseif item.activityProductIdIsExists == 1 && item.state1 == 0 && item.state2==0>可用
                <#else>不可用
                </#if>
              </td>
            </tr>
            </#list>
          </tbody>
        </table>
      </div>
      <div class="box-footer text-center" id="page_model" data-total="${productList1.pageTotal}"
             data-size="${productList1.pageSize}"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" id="selectPro_cancel">取消</button>
        <button type="button" class="btn btn-primary" data-dismiss="modal" id="selectPro_confirm">确认</button>
      </div>
    </div>
  </div>
</div>
<!--===========点击“选择商品”按钮，显示商品列表   end================--->

<div class="modal" id="preview_dialog" tabindex="-1">
  <div style="position:absolute; left:50%; top:50%; margin-left:-187.5px; margin-top:-333.5px;">
    <iframe width="375" height="667"></iframe>
    <span class="close" data-dismiss="modal"
          style="background-color: #FFF; width: 20px; height: 20px; text-align: center; line-height: 20px; opacity: 1;">&times;</span>
  </div>
</div>

</@layout_default>